package source.events.action;

import source.model.*;
import source.model.type.UnitType;
import source.model.type.ActionResult;
import source.view.MainScreen;

public class NewUnit implements Action {
	
	private int playerID;
	private UnitType uType;
	private Position whereToBePlaced;
	
	public NewUnit( int playerID, UnitType u, Position p ) {
		this.playerID = playerID;
		this.uType = u;
		this.whereToBePlaced = p;
	}
	
	public ActionResult execute( DataHandler dh ) {
		
		Unit newUnit = new Unit( uType );
		/**
		 * BEFORE THE ADD:
		 * This is where changes to the unit need to be done.
		 */
		if (!dh.addGameObject( newUnit, whereToBePlaced, playerID )) {
			MainScreen.writeToConsole("Unit was not able to be added.");
			return ActionResult.FAILED;
		}
		
		return ActionResult.SUCCESS;
	}
}
